package ch.ethz.smseth;

import java.util.List;

import android.content.Context;

public abstract class ContactUtil
{
	protected Context _ctx;
	private static ContactUtil _instance;
	
	public ContactUtil(Context ctx)
	{
		_ctx = ctx;
	}
	
	public abstract Contact fetchContactByNumber(String number);
	public abstract Contact fetchContactByName(String name);
	public abstract List<Contact> fetchContactsByName(String name);
	public abstract List<Contact> fetchContacts(String constraint);

	public static ContactUtil get(Context ctx)
	{
		if (_instance == null)
		{
			int sdkVersion = 3;
			try
			{
				sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);
			}
			catch (NumberFormatException e)
			{
				// just ignore it
			}
			
			if (sdkVersion <= 4) _instance = new ContactUtilCupcake(ctx);
			else _instance = new ContactUtilEclair(ctx);
		}
		
		return _instance;
	}
	
	public static String escape(String input)
	{
		String result = input.toString().replace("'", "''");
		return result;
	}
	
	public static class Contact
	{
		public String name;
		public String label;
		public String number;
	}
}
